package com.szholly.plug.safe.entity.role;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.*;
import com.szholly.data.general.metadata.IBaseTable;

/**
 * 定义角色与数据权限表
 */
@Component("SAFE_ROLEFUNCTION")
public class RoleFunctionService extends InterceptorTableBase implements
		IBaseTable {
	public final static String TABLE_NAME = "SAFE_ROLEFUNCTION";

	/**
	 * 获取单例对象
	 */
	public static RoleFunctionService getSingleRef() {
		return (RoleFunctionService) SpringBeanFactory
				.getBean("SAFE_ROLEFUNCTION");
	}

	@Override
	public String getMetadataTableName() {
		return TABLE_NAME;
	}

	@Override
	public String getMetadataTableAliasName() {
		return "角色与功能权限表";
	}
	
	@Override
	public String getGUIDFieldName() {
		return RoleFunctionEntity.FIELD_GUID;
	}

	private HashMap<String, Field> fields;

	@Override
	protected HashMap<String, Field> fields() {
		if (fields == null) {
			fields = new HashMap<String, Field>();

			Field itemField = new Field();

			itemField.setFieldName(RowBase.FIELD_GUID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(1);
			itemField.setFieldAliasName("全局ID");
			itemField.setCanShow(false);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(RoleFunctionEntity.FIELD_FUNCTIONID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(2);
			itemField.setFieldAliasName("功能ID");
			itemField.setIsKey(true);
			itemField.setCanShow(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(RoleFunctionEntity.FIELD_ROLEID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(3);
			itemField.setIsKey(true);
			itemField.setFieldAliasName("角色主键");
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
		}
		return fields;
	}

	/**
	 * 表分组信息
	 */
	@Override
	public String getTableGroup() {
		return "用户权限控制";
	}
}